package com.liuyk.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import androidx.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * 属性动画实现一个圆环
 * <p>
 * Created by Administrator on 2019/12/31.
 */
public class CircleSportsView extends View {
    private static final String TAG = "CircleSportsView";
    private float progress;
    private Paint mPaint;

    public CircleSportsView(Context context) {
        this(context, null);
    }

    public CircleSportsView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CircleSportsView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        init();
    }

    private void init() {
        mPaint = new Paint();
        mPaint.setColor(Color.parseColor("#22ff33"));
        mPaint.setDither(true);
        mPaint.setAntiAlias(true);
        mPaint.setStyle(Paint.Style.STROKE);//画弧线，如果不设置默认就是画了一个扇形
        mPaint.setStrokeWidth(15f);
    }

    public void setProgress(float progress) {
        this.progress = progress;
        invalidate();
    }

    public float getProgress() {
        return progress;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        //true表示经过圆心
        canvas.drawArc(0, 0, 500, 500, 0, 2 * progress, false, mPaint);
    }
}
